using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SgsUI
{
    [Serializable]
    public class NormalRes
    {
        public string sprite_normal;
        
        public Sprite sprite_pressed;

        public Sprite sprite_disabled;
    }

    public class ButtonRes : MonoBehaviour 
    {
        public string res;

        public enum Type
        {
            Simple_Btn,

            Normal_Btn,

            Common_Btn
        }

        public Type m_type = Type.Simple_Btn;

        [SerializeField] private NormalRes buttonRes;
        public NormalRes m_ButtonRes
        {
            get
            {
                if(buttonRes == null)
                {
                    buttonRes = new NormalRes();
                }
                return buttonRes;
            }
            set{buttonRes = value;}
        }

        [SerializeField] private SpriteRes target;
        public SpriteRes m_sprite
        {
            get
            {
                if(target == null)
                {
                        
                    if(TryGetComponent<SpriteRes>(out SpriteRes var_sprite))
                        target = var_sprite;
                }
                return target;
            }
            set{target = value;}
        }

        public void UpdateButtonRes()
        {
            UpdateResData();
        }

        void UpdateResData()
        {
            if(target)
            {
                if(m_type == Type.Simple_Btn)
                {
                    res = target.GetResName();
                }
                else if(m_type == Type.Normal_Btn)
                {
                    m_ButtonRes.sprite_normal = target.GetResName();
                }
            }
            else
            {
                res = String.Empty;
                m_ButtonRes.sprite_normal = String.Empty;
            } 
        }
    }
}